package org.lds.scheduled.job.admin.business.job.converter;

import org.lds.scheduled.job.admin.business.job.entity.Job;
import org.lds.scheduled.job.admin.business.job.model.request.JobBaseCreateRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Objects;

@Component
public class JobBaseCreateRequestToEntityConverter implements Converter<JobBaseCreateRequest, Job> {

    @Override
    public Job convert(JobBaseCreateRequest source) {
        LocalDateTime date = LocalDateTime.now();
        return Job.builder()
                .appId(source.getAppId())
                .triggerRuleType(source.getTriggerRuleType())
                .triggerRuleContent(source.getTriggerRuleContent())
                .name(source.getName())
                .enable((Objects.isNull(source.getTriggerRuleType()) || Objects.isNull(source.getTriggerRuleContent())) ? false : true)
                .creator(source.getCreator())
                .modifier(source.getModifier())
                .createTime(date)
                .updateTime(date)
                .build();
    }

}


